package com.neusoft.acquistion.sensor.consumer.cfg;

import com.neusoft.acquistion.sensor.consumer.entity.Monitor;
import com.neusoft.acquistion.sensor.consumer.service.IMonitorService;
import com.neusoft.acquistion.sensor.consumer.service.ISensordataService;
import com.neusoft.acquistion.sensor.consumer.util.MonitorReaderThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

@Component
public class AcquisitionStarter implements ApplicationRunner {

    @Autowired
    private IMonitorService monitorService;

    @Autowired
    private ISensordataService sensordataService;


    @Override
    public void run(ApplicationArguments args) throws Exception {
        List<Monitor> monitors = monitorService.findAll();
        monitors.forEach(monitor -> {
            if (monitor.getSn() != null && monitor.getHostname() != null) {
                new MonitorReaderThread(monitor , sensordataService);
            }
        });
    }
}
